<?php
class Edit extends Controller {
	public function json() {
		$tid = $this->post('tid', 'int');
		$num = $this->post('num', 'int');
		$product_id = $this->post('product_id', 'int');
		$name = $this->post('name', 'str');
		$original_price = $this->post('original_price', 'float');
		$market_price = $this->post('market_price', 'float');
		$real_price = $this->post('real_price', 'float');
		$description = $this->post('description', 'str');
		$start_time = $this->post('start_time', 'str');
		$end_time = $this->post('end_time', 'str');
		
		if(!$tid) $this->displayJSON(array('status' => -1, 'message' => '未知门票'));
		if(!$product_id) $this->displayJSON(array('status' => -2, 'message' => '未知景点'));
		if(!$name) $this->displayJSON(array('status' => -3, 'message' => '请输入票名'));
		if(!$real_price) $this->displayJSON(array('status' => -4, 'message' => '请输入出售价格'));

		$mTicket = new Ticket_model();
		//检查门票名称是否存在
		$params = array('name' => $name, 'id !=' => $tid, 'is_deleted' => 0);
		$result = $mTicket->info($params);
		if($result) $this->displayJSON(array('status' => -5, 'message' => '门票已存在'));
		
		$cols = array(
			'product_id' 		=> $product_id,
			'num'				=> $num,
			'name' 				=> $name,
			'original_price' 	=> $original_price,
			'market_price' 		=> $market_price,
			'real_price' 		=> $real_price,
			'description'	 	=> $description,
			'start_time' 		=> $start_time,
			'end_time' 			=> $end_time
		);
		$result = $mTicket->edit($tid, $cols);
		if($result) $this->displayJSON(array('status' => 0, 'message' => '编辑门票成功'));
		else $this->displayJSON(array('status' => -6, 'message' => '编辑门票失败'));
	}
}